#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
ll a[N], b[N];

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
void merge(ll& a1, ll& b1, ll a2, ll b2) {
  if (b1 > b2) swap(a1, a2), swap(b1, b2);
  ll x, y;
  ll a = a1, b = a2, c = b2 - b1;
  ll d = extgcd(a, b, x, y);
  a /= d, b /= d, c /= d;
  x = (__int128_t)x * c % b;
  if (x < 0) x += b;
  // x = x0 + b * t
  // ? = a1 * x + b1
  // ? = a1 * (x0 + b * t) + b1
  // ? = a1 * b * t + a1 * x0 + b1
  b1 = a1 * x + b1;
  a1 = a1 * b;
  b1 %= a1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i] >> b[i];
  rep(i, 2, n) merge(a[1], b[1], a[i], b[i]);
  cout << b[1];
  return 0;
}